// 获取支付通道
function getChannels(server,extras,callBack,isWeb){
	if(isWeb){
		var webview =mui.openWindowWithTitle({
		    url:server,
		    id:'alipay',
			waiting:{
	      		autoShow:true,//自动显示等待框，默认为true
	      		title:'正在加载...',//等待对话框上显示的提示内容
			},
			show:{
				autoShow:true,
				aniShow:'fade-in'
			}
		},{
		    title:{//标题配置
		        text:'预约挂号支付',//标题文字
		    },
		    back:{//左上角返回箭头
		        image:{
		            base64Data:''
		        },
		        click:function(){
		        	var _self =  plus.webview.getWebviewById('alipay');
		        	//_self.close();
		        	_self.canBack(function(event){
		                var canBack = event.canBack;
		                if(canBack){
		                    _self.back();
		                }else{
		                	var parentView = plus.webview.getWebviewById('registration.html');
		                	//console.log(parentView);
		                	mui.fire(parentView,'isPay',{
		                		cyyh:extras.cyyh,
		                		money:extras.money
		                	}
		                	);
		                    _self.close();
		                }
		            })
		        }
		    }
		})
	}else{
		plus.payment.getChannels(function(channels){
		var channel=channels[0];
		    //console.log(JSON.stringify(channel));
		    pay(server,extras,channel,callBack);
		},function(e){
		    alert("获取支付通道失败："+e.message);
		});
	}
}
//发起支付请求
 function pay(server,extras,channel,callback){
 	var xhr = new XMLHttpRequest();
 	xhr.onreadystatechange = function(){
 		switch(xhr.readyState){
 			case 4:
 			if(xhr.status == 200){
 				plus.payment.request(channel,xhr.responseText,function(result){
 					plus.nativeUI.alert("支付成功！",function(){
 						callback(extras);
 					});
 				},function(error){
 					plus.nativeUI.toast("支付失败：" + error.code);
 				});
 			}else{
 				plus.nativeUI.alert("获取订单信息失败，请稍后再试！")
 			}
 			break;
 			default:
 			break;
 		}
 	}
 	xhr.open('GET',server);
 	xhr.send();
 }
